/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package pl.tom.social.analyzer.gui.action;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import org.openide.DialogDescriptor;
import org.openide.DialogDisplayer;
import pl.tom.social.analyzer.gui.dialog.NewUrlDialog;
import pl.tom.social.analyzer.jade.LocalJade;
import pl.tom.social.common.types.ConversationIDType;

public final class AddNodeAction implements ActionListener {
	NewUrlDialog dialog = new NewUrlDialog();

	public void actionPerformed(ActionEvent e) {
		DialogDescriptor dd = new DialogDescriptor(dialog, "Add new node", true, new AddNodeActionListener());
		DialogDisplayer.getDefault().notifyLater(dd);
	}

	private class AddNodeActionListener implements ActionListener {

		public void actionPerformed(ActionEvent e) {
			if(e.getSource() == DialogDescriptor.OK_OPTION) {
				String link = dialog.getUrl();
				if(link != null && link.length() > 7) {
					LocalJade.getInstance().addFetcherAgent(link, ConversationIDType.AddNewNode);
				}
			}
		}
	}
}
